package com.lujieni.springbootsecurity.po;

import lombok.Data;
import lombok.RequiredArgsConstructor;
import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.authority.SimpleGrantedAuthority;
import org.springframework.security.core.userdetails.UserDetails;

import java.util.Collection;
import java.util.List;
import java.util.stream.Collectors;

/**
 * @Author：小鹿爱吃鱼
 * @Date: 2025/5/29 10:36
 * @Description: 用户登陆凭据
 */
@RequiredArgsConstructor
@Data
public class LoginUser implements UserDetails {

    private final UserDO sysUserDO;

    private final List<String> authorities;

    @Override
    public Collection<? extends GrantedAuthority> getAuthorities() {
        return authorities.stream().map(SimpleGrantedAuthority::new).collect(Collectors.toList());
    }

    public Long getUserId(){
        return sysUserDO.getId();
    }

    @Override
    public String getPassword() {
        return sysUserDO.getPassword();
    }

    @Override
    public String getUsername() {
        return sysUserDO.getUserName();
    }

    @Override
    public boolean isAccountNonExpired() {
        return true;
    }

    @Override
    public boolean isAccountNonLocked() {
        return true;
    }

    @Override
    public boolean isCredentialsNonExpired() {
        return true;
    }

    @Override
    public boolean isEnabled() {
        return true;
    }
}
